package cn.webestar.scms.user.api.dto.SysResource;

import cn.webestar.scms.commons.api.SimpleBody;
import cn.webestar.scms.user.entity.SysResource;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.util.StringUtils;

@Data
@Schema(description = "SysResourceSimpleDTO")
public class SysResourceSimpleDTO extends SimpleBody {

    @Schema(description = "父编码")
    private String pcode;

    @Schema(description = "编码")
    private String code;

    @Schema(description = "URL")
    private String url;

    @Schema(description = "名称")
    private String name;

    @Schema(description = "资源类型，1：目录、菜单，2：页面，3：接口")
    private Integer type;

    @Schema(description = "备注")
    private String remark;

    @Override
    public LambdaQueryWrapper<SysResource> toQueryWapper() {
        LambdaQueryWrapper<SysResource> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtils.hasText(pcode)) {
            queryWrapper.eq(SysResource::getPcode, pcode);
        }
        if (StringUtils.hasText(code)) {
            queryWrapper.eq(SysResource::getCode, code);
        }
        if (StringUtils.hasText(url)) {
            queryWrapper.eq(SysResource::getUrl, url);
        }
        if (StringUtils.hasText(name)) {
            queryWrapper.eq(SysResource::getName, name);
        }
        if (type!=null) {
            queryWrapper.eq(SysResource::getType, type);
        }
        if (StringUtils.hasText(remark)) {
            queryWrapper.eq(SysResource::getRemark, remark);
        }
        return queryWrapper;
    }

}
